﻿#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

#endregion

namespace Rail.Net.Core.Model.Nonpersistent
{
    [Serializable]
    [DataContract]
    public class PriceProSegment
    {
        public PriceProSegment(SearchModel searchModel, SequenceModel sequence)
        {
            SearchModel = searchModel;
            Sequence = sequence;
            PricesProTraveler = new List<PriceProTraveler>();
            foreach (var travelerModel in SearchModel.Travelers)
            {
                PricesProTraveler.Add(new PriceProTraveler(sequence, travelerModel));
            }
        }

        [DataMember]
        public SearchModel SearchModel { get; private set; }

        [DataMember]
        public SequenceModel Sequence { get; private set; }

        [DataMember]
        public List<PriceProTraveler> PricesProTraveler { get; private set; }

        [DataMember]
        public int NumberOfFreeSeats { get; set; }

        public List<PriceProTraveler> PricesProTravelerGrownup
        {
            get { return PricesProTraveler.Where(p => p.Traveler.AgeValue >= 15).ToList(); }
        }
        public List<PriceProTraveler> PricesProTravelerChild
        {
            get { return PricesProTraveler.Where(p => p.Traveler.AgeValue < 15).ToList(); }
        }

        public List<PriceProTraveler> PricesProTravelerDiscount
        {
            get { return PricesProTraveler.Where(p => p.Traveler.HasDiscount).ToList(); }
        }

        public decimal Price
        {
            get { return PricesProTraveler.Sum(p => p.TotalPrice); }
        }
    }
}